﻿
module("FallingLine.init")
test("FallingLine init", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    equal(5, fallingLine.center.x, "CenterX of FallingLine is set");
    equal(6, fallingLine.center.y, "CenterY of FallingLine is set");

    var relativeBody="";
    for (var i = 0; i < fallingLine._relativeBody.length; i++) {
        relativeBody += fallingLine._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,0) (-1,0) (1,0) (-2,0) ", relativeBody, "CenterY of FallingLine is set");

    var body= "";
    for (var i = 0; i < fallingLine.getBody.length; i++) {
        body += fallingLine.getBody[i].coordinate.toString() + " ";
    }
    equal("(5,6) (4,6) (6,6) (3,6) ", body, "CenterY of FallingLine is set");
});

test("FallingLine moveTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.moveTo(7, 8);

    deepEqual(7, fallingLine.center.x, "CenterX of FallingLine is set to new x");
    equal(8, fallingLine.center.y, "CenterY of FallingLine is set to new y");

    var relativeBody = "";
    for (var i = 0; i < fallingLine._relativeBody.length; i++) {
        relativeBody += fallingLine._relativeBody[i].coordinate.toString() + " ";
    }
    equal("(0,0) (-1,0) (1,0) (-2,0) ", relativeBody, "CenterY of FallingLine is set");

    var body = "";
    for (var i = 0; i < fallingLine.getBody.length; i++) {
        body += fallingLine.getBody[i].coordinate.toString() + " ";
    }
    equal("(7,8) (6,8) (8,8) (5,8) ", body, "CenterY of FallingLine is set");
});

test("FallingLine moveRight", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.moveRight(); 
    deepEqual(6, fallingLine.center.x, "CenterX of FallingLine is set to x+1");
    equal(8, fallingLine.center.y, "CenterY of FallingLine is same");
});

test("FallingLine moveLeft", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.moveLeft();
    deepEqual(4, fallingLine.center.x, "CenterX of FallingLine is set to x-1");
    equal(8, fallingLine.center.y, "CenterY of FallingLine is same");
});

test("FallingLine moveUp", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.moveUp();
    equal(5, fallingLine.center.x, "CenterX of FallingLine is same");
    equal(7, fallingLine.center.y, "CenterY of FallingLine is set to y-1");
});

test("FallingLine moveDown", function () {
    var x = 5;
    var y = 8;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.moveDown();
    equal(5, fallingLine.center.x, "CenterX of FallingLine is same");
    equal(9, fallingLine.center.y, "CenterY of FallingLine is set to y+1");
});

test("FallingLine rotate", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.rotate();
    equal(90, fallingLine.rotation, "Rotation of FallingLine is set to 90");
});

test("FallingLine rotate twice", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.rotate();
    equal(90, fallingLine.rotation, "Rotation of FallingLine is set to 90");
    fallingLine.rotate();
    equal(180, fallingLine.rotation, "Rotation of FallingLine is set to 180");
});

test("FallingLine rotateBack", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.rotateBack();
    equal(270, fallingLine.rotation, "Rotation of FallingLine is set to 270");   
});

test("FallingLine rotateTo", function () {
    var x = 5;
    var y = 6;
    var color = "#FF00FF";

    var fallingLine = new tetris.FallingLine(x, y, color);
    fallingLine.rotateTo(180);
    equal(180, fallingLine.rotation, "Rotation of FallingLine is set to 180");
});

